﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MySql.Data.MySqlClient;

using FnShop.Models;
using FnShop.Base.Client;

namespace FnShop.Controllers
{
    public class UsersController : Controller
    {
        /// <summary>
        /// 辅助判断的方法
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        bool AreEquals(string userName, string password)
        {
            return (userName.ToLower() == "admin" && password.ToLower() == "admin123");
        }

        //
        // GET: /Users/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Reg()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Reg(Users user)
        {
            
            using (MySqlConnection conn = new MySqlConnection (General.ConnectString))
            {
                conn.Open();
                MySqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = string.Format(@" insert into Users (UserId,Name,Password) values ('{0}','{1}','{2}')", Guid.NewGuid().ToString("N"), user.UserName, user.PassWord);
                cmd.ExecuteNonQuery();
            }

            return View();
        }


    }
}
